package com.qianfeng.smartmeeting.controller;

import com.qianfeng.smartmeeting.dto.BookingCreateDto;
import com.qianfeng.smartmeeting.service.BookingService;
import com.qianfeng.smartmeeting.utils.ResponseResult;
import com.qianfeng.smartmeeting.vo.BookingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/bookings")
public class BookingController {
    @Autowired
    private BookingService bookingService;
    
    @PostMapping
    public ResponseResult<?> createBooking(@Valid @RequestBody BookingCreateDto bookingCreateDto) {
        Long userId = 1L;//SecurityUtil.getCurrentUserId();
        return bookingService.createBooking(bookingCreateDto, userId);
    }
    
    @GetMapping("/my")
    public ResponseResult<List<BookingVo>> getMyBookings() {
        Long userId = 1L;// SecurityUtil.getCurrentUserId();
        return bookingService.getUserBookings(userId);
    }
    
    @PutMapping("/{id}/cancel")
    public ResponseResult<?> cancelBooking(@PathVariable Long id) {
        Long userId = 1L;//SecurityUtil.getCurrentUserId();
        return bookingService.cancelBooking(id, userId);
    }
}